package face.threaddemo;

import demo.java8.Person;

/**
 * Created by zhangyanfei on 2019/6/26.
 * 生产者
 *
 * @author zhangyanfei
 * @date 2019/06/26
 */
public class Consumer implements Runnable {
    private String name;
    private StorageWithBlockQueue storageWithBlockQueue;

    Consumer(String name, StorageWithBlockQueue storageWithBlockQueue) {
        this.name = name;
        this.storageWithBlockQueue = storageWithBlockQueue;
    }

    @Override
    public void run() {
        while (true) {
            try {
                System.out.println(name + "准备消费");
                Person person = (Person)storageWithBlockQueue.get();
                System.out.println(name + "已消费了(" + person.toString() + ").");
                System.out.println("===============");
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
